﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace SpectrumAnalyser.Controls.Wpf.Virtualization
{
    public class VirtualImage: IVirtualChild
    {
        private readonly Rect _bounds;
        private readonly ImageSource _imageSource;
        private UIElement _visual;

        public event EventHandler BoundsChanged;

        public VirtualImage(ImageSource imageSource)
        {
            _imageSource = imageSource;
            _bounds = new Rect(0, 0, imageSource.Width, imageSource.Height);
        }

        public Rect Bounds
        {
            get { return _bounds; }
        }

        public UIElement Visual
        {
            get { return _visual; }
        }

        public UIElement CreateVisual(VirtualCanvas parent)
        {
            if (_visual == null)
            {
                _visual = new Image() {Source = _imageSource};
            }
            return _visual;
        }

        public void DisposeVisual()
        {
            _visual = null;
        }
    }
}